﻿

app.controller('HomeChartsController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;


    $scope.GetPlaceCountByPark = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByPark'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('parkplaceview'));
                    var datalist = [];
                    for (var i = 0; i < ret.Data.length; i++) {
                        var data = ret.Data[i];
                        var obj = {
                            'name': data.ParkName,
                            'value': data.PlaceNum
                        };
                        datalist.push(obj);
                    }

                    var option = {
                        title: {
                            show: false,
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            saveAsImage: { show: true }
                        },
                        legend: {
                            show: false,
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                label: {
                                    alignTo: 'center',
                                    formatter: '{name|{b}}{c}个',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                name: '',
                                type: 'pie',
                                center: ['50%', '50%'],
                                radius: '60%',
                                data: datalist,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('placetypeview'));

                    var datalist = ret.Data;

                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left',
                            show: false
                        },
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['40%', '70%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#0E5DA6', '#1177DC'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

    }

    $scope.GetDeviceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetDeviceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('devicetypeview'));
                    var datalist = ret.Data;
                    var namelist = [];
                    var valuelist = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var data = datalist[i];
                        valuelist.push(data.value);
                        namelist.push(data.name);
                    }
                    var option = {
                        title: {
                            text: ''
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'shadow'
                            }
                        },
                        legend: { show: false },
                        grid: {
                            left: '3%',
                            right: '4%',
                            top: '3%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'value',
                            splitLine: {
                                show: false
                            },
                            show: false,
                            boundaryGap: [0, 0.01]
                        },
                        yAxis: {
                            type: 'category',
                            data: namelist
                        },
                        series: [
                            {
                                name: '设备数量',
                                type: 'bar',
                                label: {
                                    show: true
                                },
                                data: valuelist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#FF9966'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetUserCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetUserCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('usertypeview'));
                    var datalist = ret.Data;
                    var option = {
                        title: {
                            show: false,
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            saveAsImage: { show: true }
                        },
                        legend: {
                            show: false,
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}人',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                name: '',
                                type: 'pie',
                                center: ['50%', '50%'],
                                radius: '50%',
                                data: datalist,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.GetUserCountByOnline = function () {
        $http({
            method: 'POST',
            url: '../Home/GetUserCountByOnline'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('onlineview'));
                    var datalist = ret.Data;
                    var namelist = [];
                    var valuelist = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var data = datalist[i];
                        valuelist.push(data.value);
                        namelist.push(data.name);
                    }
                    var option = {
                        legend: {
                            show: false
                        },
                        tooltip: {},
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,
                            inverse: true,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 20,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            {
                                name: '',
                                type: 'line',
                                smooth: true,
                                itemStyle: {
                                    color: '#0E5DA6',
                                    borderWidth: 2,
                                    borderColor: "rgba(135, 153, 154)",
                                },
                                data: valuelist
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMonthlyCheckChart = function () {
        var model = {};
        model.PlaceType2 = [1,2,3];
        $http({
            method: 'POST',
            url: '../Home/GetCheckRecordByType',
            data: { 'PlaceType': model.PlaceType2, 'Days': 7 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var dailycount = [];
                    var weeklycount = [];
                    var monthlycount = [];
                    var exceptioncount = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].date);
                        dailycount.push(datalist[i].dailycount);
                        weeklycount.push(datalist[i].weeklycount);
                        monthlycount.push(datalist[i].monthlycount);
                        exceptioncount.push(datalist[i].exceptioncount);
                    }
                    var myChart = echarts.init(document.getElementById('checkrecordmonthlyview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            inverse: true,
                            data: namelist,//['系统实施BU', '后勤保障共享中心', '质量审核部', '采购共享中心', '用户支持BU', '工业工程部', '财务共享中心', '标推化部', '需求架构BU', '生产与运营支持', '审计部'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 12,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {
                            minInterval:1,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            {
                                name: '日检',
                                smooth: true,
                                type: 'line',
                                label: {
                                    show: true
                                },
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(83, 148, 201, 0.7)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(83, 148, 201)",
                                },
                                data: dailycount
                            },
                            {
                                name: '周检',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: weeklycount
                            },
                            {
                                name: '月检',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(145, 201, 117, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(145, 201, 117)",
                                },
                                data: monthlycount
                            },
                            {
                                name: '异常项',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(229, 63, 49, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(229, 63, 49)",
                                },
                                data: exceptioncount
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.GetStateView = function (model) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetStateView',
            data: { 'Year': model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                 
                    var myChart = echarts.init(document.getElementById('stateview'));
                    var datalist = [];
                    for (var i = 0; i < ret.Data.length; i++) {
                        var data = {
                            "name": ret.Data[i].StateName,
                            "value": ret.Data[i].Times
                        };
                        datalist.push(data)
                    }
                    var option = {
                        title: {
                            show: false,
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            saveAsImage: { show: true }
                        },
                        legend: {
                            show: false,
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}:{c}',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                name: '',
                                type: 'pie',
                                center: ['50%', '50%'],
                                radius: '50%',
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#00E5AB', '#FFCC33', '#0E5DA6', '#177cb0', '#0E5DA6', '#1177DC', '#FF6666'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                },
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetParkView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetParkView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('parkview'));
                var option = {
                    title: {
                        show: false,
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    show: true,
                    orient: 'vertical',
                    left: 'right',
                    top: 'center',
                    feature: {
                        saveAsImage: { show: true }
                    },
                    legend: {
                        show: false,
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            label: {
                                alignTo: 'labelLine',
                                formatter: '{name|{b}}:{c}',
                                minMargin: 5,
                                edgeDistance: 3,
                                lineHeight: 15,
                                rich: {
                                    time: {
                                        fontSize: 10,
                                        color: '#999'
                                    }
                                }
                            },
                            name: '',
                            type: 'pie',
                            center: ['50%', '50%'],
                            radius: '50%',
                            data: datalist,
                            itemStyle: {
                                normal: {
                                    color: function (params) {
                                        var colorList = [
                                            '#00E5AB', '#FFCC33', '#0E5DA6', '#FF6666', '#0E5DA6', '#1177DC', '#FF6666'
                                        ];
                                        return colorList[params.dataIndex]
                                    }
                                }
                            },
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetCheckYearList = function () {
        $http({
            method: 'POST',
            url: '../Home/GetCheckYearList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.CheckYearList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetDepartmentView = function (model) {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetDepartmentView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('departmentview'));
                var datalist = [];
                for (var i = 0; i < ret.Data.length; i++) {
                    var data = {
                        "name": ret.Data[i].DepartmentName,
                        "value": ret.Data[i].Times
                    };
                    datalist.push(data)
                }
                var option = {
                    title: {
                        show: false,
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    show: true,
                    orient: 'vertical',
                    left: 'right',
                    top: 'center',
                    feature: {
                        saveAsImage: { show: true }
                    },
                    legend: {
                        show: false,
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            label: {
                                alignTo: 'labelLine',
                                formatter: '{name|{b}}:{c}',
                                minMargin: 5,
                                edgeDistance: 3,
                                lineHeight: 15,
                                rich: {
                                    time: {
                                        fontSize: 10,
                                        color: '#999'
                                    }
                                }
                            },
                            name: '',
                            type: 'pie',
                            center: ['50%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetLevelView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetLevelView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('levelview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '问题等级分布',
                            type: 'pie',
                            center: ['60%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCategoryView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetCategoryView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('typeview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        show: false
                    },
                    series: [
                        {
                            name: '问题类型分布',
                            type: 'pie',
                            center: ['50%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetHiddenTroubleReport = function (model) {
        $scope.DepReportList = [];
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleDepReport',
            data: {"Year":model.Year}
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.DepReportList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitHiddenTroubleReport = function (model) {
        $scope.GetHiddenTroubleReport(model);
        $scope.GetStateView(model);
        $scope.GetParkView(model);
        $scope.GetDepartmentView(model);
        $scope.GetLevelView(model);
        $scope.GetCategoryView(model);
    }
});

